package com.example.technologia;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Spinner spin = (Spinner) (findViewById(R.id.spinner1));
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.curriencies_array,
				android.R.layout.simple_spinner_item);
		// Specify the layout to use when the list of choices appears
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// Apply the adapter to the spinner
		spin.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	public void onClick(View view) {
		Spinner spin = (Spinner) (findViewById(R.id.spinner1));
		EditText up = (EditText) (findViewById(R.id.editText1));
		EditText down = (EditText) (findViewById(R.id.editText2));
		EditText time = (EditText) (findViewById(R.id.editText3));
		switch (view.getId()) {
		case R.id.button1:
			// use this to start and trigger a service
			Intent i = new Intent(this, MyService.class);
			// potentially add data to the intent
			i.putExtra("com.example.technologia.CURRENCY", spin
					.getSelectedItem().toString());
			i.putExtra("com.example.technologia.UP", up.getText().toString());
			i.putExtra("com.example.technologia.DOWN", down.getText()
					.toString());
			i.putExtra("com.example.technologia.TIME", time.getText()
					.toString());
			this.stopService(new Intent(this, MyService.class));
			this.startService(i);
			break;
		case R.id.button2:
			this.stopService(new Intent(this, MyService.class));
			break;
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		Toast.makeText(this, "OnDestroy", 1).show();
	}

	@Override
	protected void onPause() {
		super.onPause();
		Toast.makeText(this, "OnPause", 1).show();
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		Toast.makeText(this, "OnRestart", 1).show();
	}

	@Override
	protected void onResume() {
		super.onResume();
		Toast.makeText(this, "OnResume", 1).show();
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		Toast.makeText(this, "OnSaveInstanceState", 1).show();
	}

	@Override
	protected void onStart() {
		super.onStart();
		Toast.makeText(this, "OnStart", 1).show();
	}

	@Override
	protected void onStop() {
		super.onStop();
		Toast.makeText(this, "OnStop", 1).show();
	}
}
